package utils;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.InventoryWarnBean;

/**
 * Created by Administrator on 2018/8/8.
 */

public class InventoryWarnSortUtils {

    /**
     * 物品
     * @param list
     * @param flag
     */
    public static void sortWarnGoods(List<InventoryWarnBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodName(), o1.getGoodName()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodName(), o1.getGoodName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodName(), o1.getGoodName()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodName(), o1.getGoodName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 供应商
     * @param list
     * @param flag
     */
    public static void sortWarnSupplier(List<InventoryWarnBean.DataBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
    /**
     * 规格
     * @param list
     * @param flag
     */
    public static void sortWarnSpecification(List<InventoryWarnBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
//
    /**
     * 数量
     * @param list
     * @param flag
     */
    public static void sortWarnNumber(List<InventoryWarnBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    if (o2.getStorageCount() - o1.getStorageCount() > 0) {
                        return 1;
                    } else if (o2.getStorageCount() - o1.getStorageCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    if (o2.getStorageCount() - o1.getStorageCount() < 0) {
                        return 1;
                    } else if (o2.getStorageCount() - o1.getStorageCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    /**
     * 预警值
     * @param list
     * @param flag
     */
    public static void sortWarn(List<InventoryWarnBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    if (o2.getWarningCount() - o1.getWarningCount() > 0) {
                        return 1;
                    } else if (o2.getWarningCount() - o1.getWarningCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<InventoryWarnBean.DataBean>() {
                @Override
                public int compare(InventoryWarnBean.DataBean o1, InventoryWarnBean.DataBean o2) {
                    if (o2.getWarningCount() - o1.getWarningCount() < 0) {
                        return 1;
                    } else if (o2.getWarningCount() - o1.getWarningCount() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
}
